<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/view/common/taglibs.jsp"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>${appname}-<c:if test="${!empty sessionScope._local_node_session}">${sessionScope._local_node_session.nodeName}-</c:if>${si:ctname("NET_TYPE",sessionScope._netType)}</title>
<%@ include file="/WEB-INF/view/common/css_js_ace.jsp"%>
<style type="text/css">
sample-table-1 tbody td{
  
}
</style>
<script type="text/javascript">
//计算当前页面所选中的大小
function getSize(){
	//所有的tr
	var $trs=$('#sample-table-1 tbody tr[id]');
	var size=0;
	var params=[];
	for(var i=0;i<$trs.size();i++){
		var $input=$($trs.get(i)).find("input[name='parentInput']:checked");
		var id=$($trs.get(i)).find("input[name='parentInput']").val();
		var selarr=[];
		if($input.size()==1){//如果选中
			size=size+parseInt($($trs.get(i)).find("td[name='fileSize']").attr("data"));
			selarr.push(-1);
		}else{//如果没有选中，判断是否有拆包的信息
			var $table=$($trs.get(i)).next("tr").find("table");
		    if($table.size()==0){
		    	continue;
		    }
			var $childchkarry = $table.find('input[name="childInput"]:checked').not($table.find('#checkedAll'));
			var $childallarry = $table.find('input[name="childInput"]').not($table.find('#checkedAll'));
			for(var j=0;j<$childchkarry.size();j++){
				var index=$childallarry.index($($childchkarry.get(j)));
				var fileSize=parseInt($($childchkarry.get(j)).parents("table[name='childTable'] tr").find("td[name='fileSize']").attr("data"));
				size=size+fileSize;
				selarr.push(index);
			}
		}
		if(selarr.length>0){
			params.push(id+";"+selarr.join("_"));
		}
		
	}
	return {"size":size,"params":params};
}

function packetsShow(obj){
	var nextTr=$(obj).parents("tr").next();
	if(nextTr.css("display")=='none'){
		$(obj).removeClass("icon-chevron-down").addClass("icon-chevron-up");
		nextTr.css("display","");
	}else{
		$(obj).removeClass("icon-chevron-up").addClass("icon-chevron-down");
		nextTr.css("display","none");
	}
}
function changeTab(str){
	if(str=='history'){
		 window.location="${ctx}/monitor/carved_discs_history_list.do";
	}else if(str=='upload'){
		window.location="${ctx}/monitor/carved_discs_upload_list.do";
	}else{
		window.location="${ctx}/monitor/carved_discs_manage_list.do";
	}
 
}

function mouseCoords(ev) 
{ 
	if(ev.pageX || ev.pageY){ 
	return {x:ev.pageX, y:ev.pageY}; 
	} 
	return { 
	x:ev.clientX + document.body.scrollLeft - document.body.clientLeft, 
	y:ev.clientY + document.body.scrollTop - document.body.clientTop 
	}; 
} 
$(function(){
	$('.tipMe').tooltip({'placement':'top'});
	
	$("groupMsg").toggle(
	  function () {
	    $(this).addClass("selected");
	  },
	  function () {
	    $(this).removeClass("selected");
	  }
	);
	
	$("#sample-table-1 tbody td.mytip").mouseover(function(ev){
		if($(this).find("a").size()>0){
			ev= ev || window.event; 
			var mousePos = mouseCoords(ev); 
          var $point=$(this).find("a");
         $("#roadInfo .popover-content").empty();
         var data=eval("("+$point.attr("data")+")");
         var recvAdaptorcodes=(data.recvAdaptorcode==null?"":data.recvAdaptorcode.split(","));
         var recvAdaptornames=$.trim($point.find("span[name='recvAdaptorcode']").text()).split(",");
         var recvNodecodes=(data.recvNodecode==null?"":data.recvNodecode.split(","));
         var recvNodenames=$.trim($point.find("span[name='recvNodecode']").text()).split(",");
         var sendAdaptorcode=data.sendAdaptorcode;
         var sendNodecode=data.sendNodecode;
         for(var i=0;i<recvNodecodes.length;i++){
        	 var recvNodecode=null;
        	 if(recvNodecodes[i] && recvNodenames[i]){
        		 recvNodecode=recvNodenames[i];
        	 }else{
        		 if(recvNodecodes[i]){
        			 recvNodecode=recvNodecodes[i]
        		 }else{
        			 recvNodecode="";
        		 }
        	 }
        	 var recvSyscode=recvAdaptornames[i];
        	 $("#roadInfo .popover-content").append("<span  title='发送适配器'  class='tipMe fa fa-puzzle-piece'>&nbsp;"+sendAdaptorcode+"</span>");
        	 $("#roadInfo .popover-content").append("<span class='icon-arrow-right'></span>");
        	 $("#roadInfo .popover-content").append("<span  class='tipMe icon-desktop' title='发送节点'>&nbsp;"+sendNodecode+"</span>");
        	 $("#roadInfo .popover-content").append("<span class='icon-arrow-right'></span>");
        	 $("#roadInfo .popover-content").append(" <span  class='tipMe fa fa-cloud-download' title='刻盘'>&nbsp;刻盘</span>");
        	 $("#roadInfo .popover-content").append("<span class='icon-arrow-right'></span>");
        	 $("#roadInfo .popover-content").append("<span  class='tipMe icon-desktop' title='接收节点'>&nbsp;"+recvNodecode+"</span>");
        	 $("#roadInfo .popover-content").append("<span class='icon-arrow-right'></span>");
        	 $("#roadInfo .popover-content").append("<span  title='接收适配器'  class='tipMe fa fa-puzzle-piece'>&nbsp;"+recvSyscode+"</span>");
        	 $("#roadInfo .popover-content").append("<br/>");
         }
         
         $("#roadInfo").css("left",mousePos.x-$("#roadInfo").width()/2);
		 $("#roadInfo").css("top",mousePos.y);
		 $("#roadInfo").css("display","block");
		}
	}).mouseout(function(){
		if($(this).find("a").size()>0){
			$("#roadInfo").css("display","none");
		}
	});
	
	
	$("#sample-table-1 input[name='parentInput']").click(function(){
		var selectedSize=parseInt($("#selectedSize").html());
		/* var $chkarry = $('#sample-table-1 input[name="parentInput"]:checked').not($('#checkedAll'));
		var checkedSize=0;
		if($chkarry.size()>0){
			for(var i=0;i<$chkarry.size();i++){
				var fileSize=parseInt($($chkarry.get(i)).parents("tr").find("td[name='fileSize']").attr("data"));
				checkedSize=checkedSize+fileSize;
			}
			$("#selectedSize").html($.formatByte(checkedSize));
		}else{
			$("#selectedSize").html("0");
		} */
		
		$("#selectedSize").html($.formatByte(getSize().size));
	});
	
	$("#sample-table-1 input[name='childInput']").click(function(){
		var selectedSize=parseInt($("#selectedSize").html());
		//当前table
		var $table=$(this).parents("table[name='childTable']");
		//当前tr
		var $tr=$table.parents("tr");
		var $chkarry = $table.find('input[name="childInput"]:checked').not($table.find('#checkedAll'));
		var $allarry = $table.find('input[name="childInput"]').not($table.find('#checkedAll'));
		var checkedSize=0;
		var $preTr=$tr.prev("tr");
		if($chkarry.size()!=$allarry.size()){//如果没有全部选择
			if($preTr.find("input:checked").size()==1){
				$preTr.find("input:checked").trigger("click");
			}
		}
		/* if($chkarry.size()>0){
			for(var i=0;i<$chkarry.size();i++){
				var fileSize=parseInt($($chkarry.get(i)).parents("table[name='childTable'] tr").find("td[name='fileSize']").attr("data"));
				checkedSize=checkedSize+fileSize;
			}
			$("#selectedSize").html($.formatByte(checkedSize));
		}else{
			$("#selectedSize").html("0");
		} */
		
		$("#selectedSize").html($.formatByte(getSize().size));
		
	});
});
function search(form) {
	$(form).appendPagerParaStr();
	return true;
}

function deleteById(id){
	ui.confirm('确认删除?',function(){
		 $.ajax({
			   type: "POST",
			   dataType:"json",
			   cache: false,
			   url: _ctx + "/monitor/send_cm_data_delete.do",
			   data: {id:id},
			   success: function(resp){
				   if(resp.status == '1'){
					   ui.msg(resp.msg, 1);
					   ui.go(_ctx + '/monitor/send_cm_data_list.do');
				   }else{
					   ui.msg(resp.msg, 0);
				   }
			   },
			   error:function(){
				   ui.msg('信息加载错误', 0);
			   }
		}); 
	});	
}
/**
 * 刻盘
 */
function carvedDiscs(id){
	/* var isSlected = checkAll.isChecked();
	if(!isSlected){
		ui.msg('请至少选择一条要刻盘的记录!');
		return;
	} */
	var ids = getSize().params;//checkAll.getIdsAsArr();
	if(ids.length<=0){
		ui.msg('请至少选择一条要刻盘的记录!');
		return;
	}
	window.location= _ctx + "/monitor/carved_discs_manage_carvedDiscs.do?id="+ids;
}


function deleteByBatch(){
	var isSlected = checkAll.isChecked();
	if(!isSlected){
		ui.msg('请至少选择一条要删除的记录!');
		return;
	}
	var ids = checkAll.getIdsAsArr();
	ui.confirm('确认删除?',function(){
		$.ajax({
			   type: "POST",
			   dataType:"json",
			   cache: false,
			   url: _ctx + "/monitor/send_cm_data_deletes.do",
			   traditional: true,
			   data:{ids:ids},
			   success: function(resp){
				   if(resp.status == '1'){
					   ui.msg(resp.msg, 1);
					   ui.go(_ctx + '/monitor/send_cm_data_list.do');
				   }else{
					   ui.msg(resp.msg, 0);
				   }
			   },
			   error:function(){
				   ui.msg('信息加载错误', 0);
			   }
		});
	}); 
}


/* function detail(id){
	ui.box({
		title:'详细信息',
		size: 'lg',   //sm , lg
		remote:_ctx +'/monitor/send_cm_data_get.do',
		param:{id:id}
	});
} */
</script>
</head>
<body>
<%@ include file="/WEB-INF/view/common/topbar.jsp"%>
<div class="main-container" id="main-container">
	<div class="main-container-inner">
		<%@ include file="/WEB-INF/view/common/sidebar.jsp"%>
		<div class="main-content">
			<div class="breadcrumbs" id="breadcrumbs">
				<ul class="breadcrumb">
					<li>
						<i class="icon-home home-icon"></i>
						<a href="javascript:void(0);">首页</a>
					</li>
						<li>
						<a href="javascript:void(0);">数据交换监控</a>
					</li>
					<li>
						<a href="javascript:void(0);">内外网数据监控</a>
					</li>
					<li>
						<a href="javascript:void(0);">刻盘管理</a>
					</li>
					<li class="active">刻盘管理</li>
				</ul>
			</div>

			<div class="page-content">
				<div class="row">
					<div class="col-xs-12">
						 <div class="tabbable">
							<ul class="nav nav-tabs" id="myTab">
								<li class="active">
									<a data-toggle="tab" href="#home" onclick="changeTab('download')">
										<i class="green icon-cloud-download bigger-110"></i>
										刻盘管理
									</a>
								</li>
								<li>
									<a data-toggle="tab" href="#" onclick="changeTab('history')">
									  <i class="icon-cloud bigger-110"></i>
										刻盘历史
									</a>
								</li>
								<li>
									<a data-toggle="tab" href="#" onclick="changeTab('upload')">
									  <i class="icon-cloud-upload bigger-110"></i>
										上传管理
									</a>
								</li>
							</ul>
						<div class="tab-content">		
						<div class="widget-box">
								<div class="widget-header header-color-white">
							<a class="right"></a>
								<div class="widget-toolbar no-border">
								   <a href="#" data-action="collapse">
										<i class="icon-chevron-up"></i>
									</a>
								</div>
							</div>

							<div class="widget-body">
								<div class="widget-main">
								     <div class="alert alert-info">
										<button class="close" data-dismiss="alert" type="button">
										  <i class="icon-remove"></i>
										</button>
										<i class="icon-hand-right green"></i>
										1.下载后如要刻盘，请勿修改下载后的文件名和文件内容，否则将可能无法进行后续的交换处理！
										<br/>
										<i class="icon-hand-right green"></i>
										2. 刻盘后需在<span class="red"><c:choose>
										 <c:when test="${isInnerCode }">外网 </c:when>
										 <c:otherwise>内网</c:otherwise>
										</c:choose>
										</span>进行光盘读取，并在<span class="red"><c:choose>
										 <c:when test="${isInnerCode }">外网 </c:when>
										 <c:otherwise>内网</c:otherwise>
										</c:choose></span>数据交换平台（${localNode.nodeName}）上传文件，以便完成后续交换处理！
									</div>
								
									<form id="searchForm" class="form-search" action="${ctx}/monitor/carved_discs_manage_list.do" method="post"  onsubmit="return search(this)">
										<div class="row">
											<div class="col-xs-4">
												<div class="input-group">
													<span class="input-group-addon">数据类型</span>
													<input class="form-control" type="text" name="sendBusicode" value="${param.sendBusicode}"/> 
												</div>
											</div>
											<div class="col-xs-4">
												<div class="input-group">
													<span class="input-group-addon">批次号</span>
													<input class="form-control" type="text" name="batchCode" value="${param.batchCode}"/> 
												</div>
											</div>
										</div>
										<div class="row mg-top12">
											<div class="col-xs-4">
												<div class="input-group">
													<span class="input-group-addon">开始时间</span>
													<span class="input-icon input-icon-right width-100">
													<input type="text" class="input-cal"   id="startCreated" name="startCreated" value="${param.startCreated}" 
														onfocus="WdatePicker({onpicked:function(){endCreated.focus();},dateFmt:'yyyy-MM-dd HH:mm:ss',isShowWeek:true,maxDate:'#F{$dp.$D(\'endCreated\');}'})"
														style=""/>
													<i class="icon-calendar blue pointer" onclick="javascript:$('#startCreated').focus();"></i>
													</span>
												</div>
											</div>
											<div class="col-xs-4">
												<div class="input-group">
													<span class="input-group-addon">结束时间</span>
													<span class="input-icon input-icon-right width-100">
													<input type="text" class="input-cal" id="endCreated" name="endCreated" value="${param.endCreated}" 
														onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',isShowWeek:true, minDate:'#F{$dp.$D(\'startCreated\');}'})"/>
													<i class="icon-calendar blue pointer" onclick="javascript:$('#endCreated').focus();"></i>
													</span>
												</div>
											</div>
											<div class="col-xs-4">
												<div class="input-group">
													<span class="input-group-btn">
														<button type="submit" class="btn btn-purple btn-sm">
															<i class="icon-search icon-on-right bigger-110"></i>
															搜索
														</button>&nbsp;&nbsp;
														<a href="${ctx}/monitor/carved_discs_manage_list.do" class="btn btn-purple btn-sm">
															<i class="icon-refresh icon-on-right bigger-110"></i>
															清空
														</a>
													</span>
												</div>
											</div>
										</div>
									</form>
								</div>
							</div>
						</div>
						
						<div class="hr hr12 hr-dotted"></div>
						<div class="alert alert-info">
						  
							<a class="btn btn-primary btn-xs" href="javascript:void(0)" onclick="carvedDiscs()"><i class="icon-download bigger-120"></i> 下载刻盘&nbsp;</a>
									<i class="icon-bell "></i>
							  待刻盘文件总大小为：<small class="danger">${si:formatByte(filesize) }</small>，已选择文件大小：<span style="color: red;" id="selectedSize">0B</span>
							<a href="#" title="刷新" class="tipMe btn btn-xs btn-info pull-right" onclick="javascript:$.refresh();">
														<i class="icon-refresh"></i>刷新
													</a>
						</div>
                             <div class="pull-left">
								<p><span class="badge badge-info"> <i class="icon-info-sign"></i>  路由图例说明 </span>&nbsp;&nbsp;&nbsp;&nbsp;
								<span class=""><span  title="适配器"  class="tipMe fa fa-puzzle-piece"></span>&nbsp;适配器</span>&nbsp;&nbsp;&nbsp;&nbsp;
								<span class=""><span  title="节点"  class="tipMe icon-desktop"></span>&nbsp;节点</span>&nbsp;&nbsp;&nbsp;&nbsp;
								<span class=""><span  title="刻盘"  class="tipMe fa fa-cloud-download"></span>&nbsp;刻盘</span>&nbsp;&nbsp;&nbsp;&nbsp;
								<span class=""><span  title="网闸"  class="tipMe fa fa fa-shield"></span>&nbsp;网闸</span>&nbsp;&nbsp;&nbsp;&nbsp;
								<span class=""><span  title="路线指向"  class="tipMe icon-arrow-right"></span>&nbsp;路线指向</span></p>
							</div>                                           

						
						<div class="table-responsive">
							<table id="sample-table-1" class="table table-striped table-bordered table-hover">
								<thead>
									<tr>
										<th class="center">
											<label>
											<input type="checkbox" name="parentInput" class="ace" id="checkedAll"/>
											<span class="lbl"></span>
											</label>
										</th>
										<th style="white-space: nowrap;">序号</th>
										<th style="white-space: nowrap;">交换请求编号</th>
										<th style="display: none;" >请求批次号</th>
										<th style="white-space: nowrap;">数据类型</th>
										<th style="white-space: nowrap;">审核人</th>
										<th style="white-space: nowrap;">交换路由信息</th>
										<th style="white-space: nowrap;">交换请求时间</th>
										<th style="white-space: nowrap;">文件总大小</th>
										<th style="white-space: nowrap;">文件打包信息</th>
										<th style="white-space: nowrap;">是否拆包</th>
									</tr>
								</thead>

								<tbody>
									<c:forEach var="vo" items="${_data}" varStatus="sta">
									<tr id="msg_${vo.id}"> 
										<td class="center">
											<label>
											<%-- <c:if test="${vo.sendStatus == '0' || vo.sendStatus == '1' || vo.sendStatus == '3'}"> --%>
											<input type="checkbox" name="parentInput" class="ace" value="${vo.id}"/>
											<%-- </c:if> --%>
											<span class="lbl"></span>
											</label>
										</td>
										 <td class="center">
									       ${sta.count}
									    </td>
									    <td style="width: 10%;">
									      ${vo.batchId }  
									    </td>
									    <td style="display: none;">
									      ${vo.batchId }             
									    </td>
										<td><span title="${si:dataName(vo.sendBusicode) }">${si:dataName(vo.sendBusicode) }</span></td>
										<td><span title="${vo.auditPerson}">${vo.auditPerson}</span></td>
										<td class="left mytip" >
												  <c:if test="${fn:contains(vo.recvNodecode,',') }">
												                 一点多发                          <a data-action="collapse" href="#" style="position: absolute;" 
												                     data="{sendNodecode:'${si:nodeName(vo.sendNodecode)}',recvNodecode:'${vo.recvNodecode }',
												                     sendAdaptorcode:'${si:adaptorName(vo.sendAdaptorcode)}',recvAdaptorcode:'${vo.recvAdaptorcode}'}">
																	   <i class="icon-eye-open">
																	   </i>
																		<span name="recvNodecode" style="display: none;">
																			<c:forEach var="code" items="${fn:split(vo.recvNodecode,',')}" varStatus="sta">
																			   ${si:nodeName(code)},
																			</c:forEach>
																		</span>
																		<span name="recvAdaptorcode" style="display: none;">
																			<c:forEach var="code" items="${fn:split(vo.recvAdaptorcode,',')}" varStatus="sta">
																			   ${si:adaptorName(code)},
																			</c:forEach>
																		</span>
																	</a>
												  </c:if>
												  <c:if test="${!fn:contains(vo.recvNodecode,',') }">
												     <span  title="发送适配器"  class="tipMe fa fa-puzzle-piece">&nbsp;${si:adaptorName(vo.sendAdaptorcode)}</span>
												     <span class="icon-arrow-right"></span>
												     <span  class="tipMe icon-desktop" title="发送节点">&nbsp;${si:nodeName(vo.sendNodecode)}</span>
												     <span class="icon-arrow-right"></span>
												     <span  class="tipMe fa fa-cloud-download" title="刻盘">&nbsp;刻盘</span>
												     <span class="icon-arrow-right"></span>
												     <span  class="tipMe icon-desktop" title="接收节点">&nbsp;${si:nodeName(vo.recvNodecode)}</span>
												     <span class="icon-arrow-right"></span>
												     <span  title="接收适配器"  class="tipMe fa fa-puzzle-piece">&nbsp;${si:adaptorName(vo.recvAdaptorcode)}</span>
												  </c:if>
												  
										</td>
										<td>${si:fmtDate(vo.requestDate)}</td>
										<td name="fileSize" data="${vo.zipSize}">${si:formatByte(vo.zipSize) }</td>
										<td><%-- ${si:formatterFile(vo.filepaths)} --%> ${vo.zipName }</td>
										<td style="white-space: nowrap;"><c:if test="${vo.packets!='' && vo.packets!=null}">
											  <button onclick="packetsShow(this)"  class="btn-primary btn-xs icon-chevron-down">
											        查看拆包
										      </button>
										    </c:if>
										    <c:if test="${vo.packets==null || ''==vo.packets}">无拆包</c:if>
										</td>
										
									</tr>
									<c:if test="${vo.packets!='' && vo.packets!=null}">
									<tr style="display: none;" name="parentTr">
										 <td colspan="10">
										     <table name="childTable" class="table  table-bordered table-hover">
										        <caption>文件${vo.zipName }拆包信息列表</caption>
										         <thead>
													<tr>
														<th class="center">
															<label>
															<input type="checkbox" name="childInput" class="ace" id="checkedAll"/>
															<span class="lbl"></span>
															</label>
														</th>
														<th style="white-space: nowrap;">序号</th>
														<th style="white-space: nowrap;">描述</th>
														<th style="white-space: nowrap;" >拆包文件</th>
														<th style="white-space: nowrap;" >大小</th>
														<th style="white-space: nowrap;" >状态</th>
													</tr>
												  </thead>
												  <tbody>
													<c:forEach items="${fn:split(vo.packets,',') }" varStatus="st" var="packet">
											          <tr>
											             <td class="center">
															<label>
															<%-- <c:if test="${vo.sendStatus == '0' || vo.sendStatus == '1' || vo.sendStatus == '3'}"> --%>
															<input type="checkbox" name="childInput" class="ace" value="${st.index}"/>
															<%-- </c:if> --%>
															<span class="lbl"></span>
															</label>
														 </td>
														 <td>
														    ${st.count }
														 </td>
														 <td>
														   打包文件的第${st.count }个拆包文件
														 </td>
														 <td>
														  ${packet }
														 </td>
														  <td name='fileSize' data="${fn:split(vo.packetsSize,',')[st.index] }">
														  ${si:formatByte(fn:split(vo.packetsSize,',')[st.index]) }
														 </td>
														  
														  <c:if test="${fn:split(vo.status,',')[st.index]=='1'}">
														  <td>
														   已刻过盘
														   </td>
														  </c:if>
														   <c:if test="${fn:split(vo.status,',')[st.index]=='0'}">
														     <td style="color: red;  ">
														   未刻盘
														   </td>
														  </c:if>
														  
														 
											          </tr>
											        </c:forEach>
											       </tbody>
										     </table>
										</td>
									 </tr>
									 </c:if>
									</c:forEach>
								</tbody>
							</table>
							<jsp:include page="/WEB-INF/view/common/pg.jsp">
								<jsp:param value="${ctx}/monitor/carved_discs_manage_list.do" name="url"/>
								<jsp:param value="${_total}" name="total"/>
								<jsp:param value="${_urlpara}" name="urlpara" />
							</jsp:include>
						</div>
					  </div>
					</div>
				</div>
			</div>
		</div>
	</div>
	</div>
</div>
<div class="popover fade bottom in" style="display: none;" id="roadInfo">
	<div class="arrow"></div>
	<h3 class="popover-title">一点多发路由</h3>
	<div class="popover-content"> Heads up! This alert needs your attention, but it's not super important.</div>
</div>

</body>
</html>
